//
//  ExplosiveGoodsCollectionViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/7/25.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit
import EasyPeasy

class ExplosiveGoodsCollectionViewCell: UICollectionViewCell {

    var loginClosure:TouchBlock!
    
    var backGoodsId : BackIntValue!
    
    @IBOutlet weak var baseView: UIView!
    @IBOutlet weak var img: UIImageView!
    @IBOutlet weak var goodsName: UILabel!
    @IBOutlet weak var nowPrice: UILabel!
    @IBOutlet weak var bazaarPrice: UILabel!
    
    var goodsModel:SiteGoodsModel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code

        self.baseView.setShadow(color: "000000", offset: CGSize.init(width: 0, height: 1.5), radius: 3, opacity: 0.15)
        self.baseView.setCornerRadio(radio: 10, isMask: false)
        self.img.corner(byRoundingCorners: [.topLeft,.topRight], radii: 10)
    }
    
    func reload(withModel model:SiteGoodsModel){
        self.goodsModel = model
        self.img.my_setImage(url: model.img, placeholder: Api.placeHolder.rawValue)
        self.goodsName.text = model.name
        self.nowPrice.attributedText = Utils.changeLabelTextFontSize(normalString: "￥" + "\(model.price)" + "/" + model.spec, changeString: "\(model.price)".getPriceInteger(), font: UIFont.systemFont(ofSize: 17))
        self.bazaarPrice.attributedText = Utils.labelTextDeleLine(normalString: "市场价：￥\(model.marketPrice)", deleString: "￥" + "\(model.marketPrice)")
    }
    
    
    
    @IBAction func addButtonClick(_ sender: UIButton) {
        guard Utils.isLogined() else{
            PKhud.showText(text: "请先登录~")
            if self.loginClosure != nil {
                self.loginClosure()
            }
            return
        }
        if self.backGoodsId != nil {
            self.backGoodsId(self.goodsModel.id)
        }
    }
    

}
